import {Component, Inject, OnInit, Optional} from '@angular/core';
import {_HttpClient} from '@delon/theme';
import {DomSanitizer} from '@angular/platform-browser';
import {ActivatedRoute} from '@angular/router';
import {appConfig} from '../../../../service/common';
import {UtilityService} from '../../../../service/utils.service';
import {ReuseTabService} from '@delon/abc';

@Component({
  selector: 'app-interurl',
  templateUrl: './interurl.component.html',
})
export class InterurlComponent implements OnInit {
    public orbitUrl: string;
    constructor(
        private http: _HttpClient,
        private utilityService: UtilityService,
        private sanitizer: DomSanitizer,
        public activatedRoute: ActivatedRoute,
        @Optional() @Inject(ReuseTabService) private reuseTabService: ReuseTabService,
    ) {
     }

    appGuid: string;
    appName: string;
    ngOnInit() {
        this.activatedRoute.queryParams.subscribe(queryParams => {
            this.appGuid = queryParams.appGuid;
            this.getAppDetail(this.appGuid);
        });

    }

    getAppDetail(guid) {
        this.utilityService.getData(appConfig.serverUrl + appConfig.API.getSwagger + '/' + guid)
            .subscribe(
                (val) => {
                    this.orbitUrl = 'http://' + val.result;
                    console.log(this.orbitUrl)
                    /*this.appName = val.result.appName;
                    this.reuseTabService.title = this.appName + '-API详情'
                    this.orbitUrl = 'http://' + val.result.ipAddr + ':' + 1 +  val.result.ipPort + '/swagger-ui.html#/';
                    console.log(this.orbitUrl)*/
                }
            );
    }

}
